#!/bin/sh

# Copyright (C) 2020 user18130814200115-2
# Copyright (C) 2021 Kevin "The Nuclear" Bloom <nuclearkev@dragora.org>
#
# This file is part of libre-bible (LB).
#
# LB is free software: you can redistribute it and/or modify
# it under the terms of the 2-Clause BSD License.
#
# LB is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# 2-Clause BSD License for more details.
#
# You should have received a copy of the 2-Clause BSD License
# along with LB.  If not, see <https://opensource.org/licenses/BSD-2-Clause>.


echo "[" > output.txt

for verse in $(seq 1 1 51)
do
    if [ $verse -lt 10 ]
    then
        num="0${verse}"
    else
        num=${verse}
    fi

    file_name=SIR${num}.htm

    wget https://ebible.org/eng-kjv/${file_name}


    echo "[" >> output.txt
    html2text -width 1000 ${file_name} | while read line
    do
        if [[ ${line:0:1} =~ ^[0-9]+$ ]]
        then
            IFS=' ' read -raarr <<< "${line}"
            if ! [[ ${arr[1]} = "" ]]
            then
                echo "\"${arr[1]}\"," >> output.txt
            fi
        fi
    done
    echo "\"END OF CHAPTER\"]," >> output.txt
done

echo "]" >> output.txt

tr -d '\n' < output.txt > output.txt

rm *.htm
